package com.huan.drools.controller;

import com.huan.drools.DroolsManager;
import com.huan.drools.DroolsManager2;
import com.huan.drools.entity.DroolsRule;
import com.huan.drools.service.DroolsRuleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 控制层
 *
 * @author huan.fu
 * @date 2022/5/27 - 14:36
 */
@RestController
@RequestMapping("/drools/rule")
public class DroolsRuleController2 {

    @Resource
    private DroolsManager2 droolsManager2;

    @GetMapping("findAll2")
    public String findAll() {

        return "ok";
    }

    @PostMapping("addOrUpdate")
    public String addOrUpdate(@RequestBody DroolsRule droolsRule) {
        droolsManager2.addOrUpdateRule(droolsRule);
        return "添加成功";
    }

    @PostMapping("/deleteRule2")
    public String deleteRule(@RequestBody DroolsRule droolsRule, String ruleName) {
        droolsManager2.deleteDroolsRule(droolsRule, ruleName);
        return "删除成功";
    }

    @GetMapping("/fireRule2")
    public String fireRule(String kieBaseName, Integer param) {
        return droolsManager2.fireRule(kieBaseName, param);
    }

    @GetMapping("/print2")
    public String print(String kieBase) {
        droolsManager2.printRule(kieBase);
        return "ok";
    }
}


